/**
 * Created by Administrator on 2015/4/19.
 */

var express = require('express');
var router = express.Router();
var http = require('http').Server(router);
var io = require('socket.io')(http);
router.get('/', function(req, res, next) {

    res.render('mychat');
});
var users={};
io.sockets.on('connection', function(socket){
    socket.on('login',function(data){
        if(data in users){

        }else{
            var nickname = data;
            users[nickname]= socket;
        }
    });
    console.log('a user connected');
    socket.on('chat message', function(msg){
        console.log('message: ' +msg);
        io.emit('chat message',  "yousid:"+msg);

           io.emit('sever chat',msg);


    });


});

var server = http.listen(4000, function() {
    console.log('start at port:' + server.address().port);
});
module.exports = router;
